package com.learn.controller;

import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learn.entity.SysUser;
import com.learn.mapper.SysUserMapper;
import com.learn.service.LearnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangjianshan on 2021-05-01
 */
@Api
@RestController
@RequiredArgsConstructor
@Value
public class LearnController {
    SysUserMapper sysUserMapper;
    LearnService learnService;

    @GetMapping("/getAllUsers")
    public List<SysUser> getAllUsers() {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUsername, "admin");
        Page<SysUser> page = new Page<SysUser>(1, 2);
        learnService.page(page, queryWrapper);
        return sysUserMapper.selectList(queryWrapper);
    }

    @ApiOperation("插入")
    @PostMapping("/createSysUser")
    public int createSysUser() {
        return sysUserMapper.insert(SysUser.niu().setUsername(UUID.randomUUID() + ""));
    }


    @ApiOperation("修改")
    @PostMapping("/updateUser")
    public int updateUser() {
        SysUser sysUser = SysUser.niu().setUserId(1388508694406090754L);
        return sysUserMapper.updateById(sysUser);
    }
}
